window.onload = function () {
    axios.defaults.withCredentials = true;
//获取内容
let kh_login = document.getElementById("kh_login")
let kh_count = document.getElementById("kh_count")
let kh_oldpassword = document.getElementById("kh_oldpassword")
let kh_newpassword = document.getElementById("kh_newpassword")
let kh_newpasswordtoo = document.getElementById("kh_newpasswordtoo")
let kh_myyzm = document.getElementById("kh_myyzm")
//获取验证码
getCode();
$('.kh_yzmup').click(function () {
    console.log(1);
    getCode();
})
$(kh_login).on('click', function (event) {
    event.preventDefault()
    if (kh_count.value && kh_oldpassword.value && kh_myyzm.value && kh_newpassword.value && kh_myyzm.value) {
        axios.post('https://elm.cangdu.org/v2/changepassword', {
            username: kh_count.value,
            oldpassWord: kh_oldpassword.value,
            newpassword: kh_newpassword.value,
            confirmpassword: kh_newpasswordtoo.value,
            captcha_code: kh_myyzm.value
        }).then(res => {
            console.log(res);
            if(res.data.status==1){
                Toast('success',res.data.success);
            }else if(res.data.status==0)
            {
                Toast('warning',res.data.message);
            }



        })
    
    } else if (kh_count.value == '') {
        Toast('warning','请输入正确账号');
    } else if (kh_oldpassword.value == '') {
        Toast('warning','请输入老密码');
    } else if (kh_newpassword.value == '') {
        Toast('warning','请输入新密码');
    } else if (kh_newpasswordtoo.value == '') {
        Toast('warning','请输入确定密码');
    } else if (kh_myyzm.value == '') {
        Toast('warning','请输入验证码');
    }
})





function getCode() {
    // $().ajax({
    //     url: 'https://elm.cangdu.org/v1/captchas',
    //     method: 'POST',
    //     success: res => {
    //         $('.kh_yzmup').child('img').attr('src', res.code);
    //     }
    // })
    axios.post('https://elm.cangdu.org/v1/captchas').then(data => {
        console.log(data)
        var lists = data.data.code;
    
        $('.kh_yzmup').html(`<img class="kh_yzmpic" src="${lists}">
        <span class='kh_yzma' style="font-size: 0.2rem;">看不清<p
          style="color: #3b95e9;">换一张</p>
      </span>
        `) //验证码图片渲染到了界面

    })
}

}